﻿using System;
using System.Collections;
using System.Text;
using System.Configuration;

using Intergr8.Data;

namespace Intergr8.Data.DataManagement
{
    /// <summary>
    /// Provide Initialisation and Fetch wrappers around the configured Data Sources
    /// </summary>
    public class DataSourceManager
    {
        private IEnumerator _currentProvider = null;

        public System.Data.DataTable Fetch(string datasourcename)
        {

            DataProvider datasource = null;

            _currentProvider = DataProviderManager.Providers.GetEnumerator();

            bool nextProvider = _currentProvider.MoveNext();
            while (nextProvider == true)
            {
                datasource = (DataProvider)_currentProvider.Current;
                if (datasource.Name.Equals(datasourcename,StringComparison.CurrentCultureIgnoreCase))
                {
                    return datasource.Fetch();
                }
                nextProvider = _currentProvider.MoveNext();
            }
            return null;

        }
    }
}
